
/*
 * This is the extension activity for the 'receive' activity associated
 * with service '{http://www.pi4soa.org/PingExample}Server'
 * and behavior 'PingExampleProcess'. The name of the receive
 * activity is 'PingRequestRequestExchange'.
 */
package org.pi4soa.pingexample.server.pingexampleprocess;

import java.util.List;

import org.pi4soa.service.extensions.DefaultActivityExtension;
import org.pi4soa.service.extensions.ReceiveActivityExtension;
import org.pi4soa.service.extensions.ExtensionContext;
import org.pi4soa.service.Identity;
import org.pi4soa.service.Message;
import org.pi4soa.service.ServiceException;

/**
 * This class has been autogenerated to implement the custom
 * receive activity within a service endpoint description.
 */
public class PingRequestRequestExchangeReceive extends DefaultActivityExtension
					implements ReceiveActivityExtension {

	/**
	 * The constructor for the receive activity extension.
	 */
	public PingRequestRequestExchangeReceive() {
	}
	
	/**
	 * This method enables an activity extension to
	 * process a received message.
	 * 
	 * @param context The context
	 * @param message The received message
	 * @exception ServiceException Failed to process message
	 */
	public void processMessage(ExtensionContext context,
					Message message) throws ServiceException {

		
		System.out.println("Server: Received ping request: " + message.getValue());
		
		List<Identity> messageIdentities = message.getMessageIdentities();
		System.out.println("Identities:");
		for(Identity identity : messageIdentities) {
			System.out.println("Identity. Name: " + identity.getName() + ", FullId: " + identity.getFullId() + ", Id: " + identity.getId() + ": ");
			for(Object object : identity.getValues()) {
				System.out.println(object);
			}
		}
		
		java.io.Serializable variable = "<pingResponse ID=\"" + message.getMessageIdentity("Ping") + "\">ping reply</pingResponse>";
		System.out.println("Server: Setting Variable: " + variable);
		
		context.setVariable("pingResponse", variable);
		// TODO: Add code to process the supplied message.

	}
}	